package main

import (
	"image"
	"log"
	"net/http"

	"github.com/kbinani/screenshot"
)

var (
	quality      = 80                     // JPEG质量(1-100)
	frameRate    = 60                     // 帧率(FPS)
	screenBounds = image.Rect(0, 0, 0, 0) // 屏幕尺寸
)

func main() {
	// 初始化截屏区域
	if n := screenshot.NumActiveDisplays(); n <= 0 {
		log.Fatal("未检测到活动显示器")
	}
	screenBounds = screenshot.GetDisplayBounds(0)

	// 启动截屏服务
	go startCaptureService()

	// 设置路由
	http.HandleFunc("/stream", streamHandler)
	// main.go (修改后的部分)
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		// 从嵌入的文件系统 'indexHTML' 中读取文件
		content, err := indexHTML.ReadFile("index.html")
		if err != nil {
			http.Error(w, "Internal Server Error", http.StatusInternalServerError)
			return
		}
		w.Header().Set("Content-Type", "text/html")
		w.Write(content)
	})

	// 启动服务器
	log.Println("服务启动: http://localhost:8080")
	log.Fatal(http.ListenAndServe(":8080", nil))
}
